<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>选择商品</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css">
    <link rel="stylesheet" href="/static/css/style.css">
    <script src="/static/layui/jquery.min.js"></script>
    <script src="/static/layui/layui.js"></script>
    <script src="/static/js/xyl.js"></script>
</head>
<body>
<div class="layui-card">
    <div class="layui-card-body">
        <fieldset class="layui-elem-field">
            <legend>条件搜索</legend>
            <div class="layui-field-box">
                <form class="layui-form layui-form-pane" action="{:url('/store/user')}" method="GET">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">输入关键字</label>
                            <div class="layui-input-inline">
                                <input type="text" name="keyword" placeholder="请输入用户名或手机号" autocomplete="off"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <button class="layui-btn" lay-submit lay-filter="search">搜索</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
        <form class="layui-form">
            <table class="layui-table">
                <thead>
                <tr>
                    <th><input type="checkbox" lay-skin="primary" title="全选" id="parent" lay-filter="parent"></th>
                    <th>头像</th>
                    <th>会员等级</th>
                    <th>昵称</th>
                    <th>性别</th>
                    <th>手机号</th>
                    <th>状态</th>
                    <th>注册时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                {foreach $list as $vo}
                <tr>
                    <td><input type="checkbox" lay-filter="son" class="son" lay-skin="primary" value="{$vo.id}"
                               title="{$vo.id}"></td>
                    <td><img src="{$vo.avatar}" class="layui-circle layui-view-img"></td>
                    <td>{$vo.grade_name}</td>
                    <td>{$vo.nickname}</td>
                    <td>{$vo.gender}</td>
                    <td>{$vo.phone}</td>
                    <td>
                        {notempty name='$vo.status'}
                        <span class="layui-font-red">禁用</span>
                        {else/}
                        <span class="layui-font-green">启用</span>
                        {/notempty}
                    </td>
                    <td>{$vo.register_time}</td>
                    <td>
                        <a class="layui-btn layui-btn-sm edit" data-url="{:url('/store/user/edit',['id'=> $vo.id])}"
                           data-title="编辑会员"
                           data-w="800px"
                           data-h="700px">编辑</a>
                    </td>
                </tr>
                {/foreach}
                </tbody>
            </table>
        </form>
    </div>
</div>
<script>
    layui.use('form', function () {
        var form = layui.form;
        form.on('checkbox(parent)', function (data) {
            selected(data.elem.checked);
        })

        function selected(checked) {
            $('.son').each(function () {
                $(this).prop('checked', checked);
            });
            form.render('checkbox');
        }

        form.on('checkbox(son)', function (data) {
            sonSelected();
        })

        function sonSelected() {
            let son = $('.son');
            let count = 0;
            son.each(function () {
                if ($(this).prop('checked')) {
                    count++;
                }
            });

            $('#parent').prop('checked', son.length == count);
            form.render('checkbox');
        }

    });
</script>
</body>
</html>
